<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>认证列表</title>
    <%@ include file="inc/css.jsp" %>
</head>

<body>
<div id="posts" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">认证列表</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <a href="javascript:void(0)" onclick="_companyUserList.fn.batchDel(1)" class="btn btn-outline btn-danger btn-lg" role="button">一键通过</a>
                        <a href="javascript:void(0)" onclick="_companyUserList.fn.batchDel(2)" class="btn btn-outline btn-danger btn-lg" role="button">一键驳回</a>

                        <form class="navbar-form navbar-right" role="search">
                            <div class="form-group">
                                <input type="text" class="form-control" id="mobile" maxlength="20" placeholder="账号"/>
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control" id="nickName" maxlength="20" placeholder="名称"/>
                            </div>
                            <div class="form-group">
                                <label>认证类型：</label>
                                <select id="typeList" style="width: 120px;" class="form-control">
                                    <option value="">全部</option>
                                    <option value="1">个人</option>
                                    <option value="2">企业</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>状态：</label>
                                <select id="statusList" style="width: 120px;" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">待审核</option>
                                    <option value="1">审核成功</option>
                                    <option value="2">审核失败</option>
                                </select>
                            </div>
                            <button type="button" id="c_search" class="btn btn-primary btn-sm">搜索</button>
                        </form>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">

                        <div class="table-responsive">

                            <table class="table table-striped table-bordered table-hover" id="dataTables">
                                <colgroup>
                                    <col class="gradeA even" style="width: 3%"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th><input type="checkbox" onclick="$leoman.checkAll(this)" class="checkall"/></th>
                                    <th>账号</th>
                                    <th>提交时间</th>
                                    <th>认证类型</th>
                                    <th>名称</th>
                                    <th>审核状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->

<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">审核失败原因</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="companyUserId"/>
                <input type="hidden" id="tempCheckStatus" value=""/>
                <textarea id="failReasonContent" cols="40" rows="6" class="form-control" style="resize: none;"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="_companyUserList.fn.batchCheck()" class="btn btn-primary">确定</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<%@ include file="inc/footer.jsp" %>
</body>

<script type="text/javascript">
    var _companyUserList = {
        v: {
            id: "_companyUserList",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                _companyUserList.fn.dataTableInit();

                // 查询
                $("#c_search").click(function () {
                    _companyUserList.v.dTable.ajax.reload();
                });
            },
            dataTableInit: function () {
                _companyUserList.v.dTable = $leoman.dataTable($('#dataTables'), {
                    "processing": true,
                    "serverSide": true,
                    "searching": false,
                    "ordering": false,
                    "ajax": {
                        "url": "backend/companyUser/list",
                        "type": "POST"
                    },
                    "columns": [
                        {"data": "id"},
                        {"data": "mobile"},
                        {
                            "data": "sendTime",
                            render: function (data) {
                                if (null != data && data != '') {
                                    return formatJsonDateTime(data, 'yyyy-MM-dd hh:mm:ss');
                                } else {
                                    return '';
                                }
                            }
                        },
                        {
                            "data": "type",
                            render: function (data) {
                                var showName = "";
                                switch (Number(data)) {
                                    case 0:
                                        showName = "";
                                        break;
                                    case 1:
                                        showName = "个人";
                                        break;
                                    case 2:
                                        showName = "企业";
                                        break;
                                }
                                return showName;
                            }
                        },
                        {"data": "nickName"},
                        {
                            "data": "checkStatus",
                            render: function (data) {
                                var showName = "";
                                switch (Number(data)) {
                                    case 0:
                                        showName = "待审核";
                                        break;
                                    case 1:
                                        showName = "审核成功";
                                        break;
                                    case 2:
                                        showName = "审核失败";
                                        break;
                                }
                                return showName;
                            }
                        },
                        {"data": ""}
                    ],
                    "columnDefs": [
                        {
                            "data": null,
                            "defaultContent": "<a title='查看详情' class='btn btn-primary btn-circle edit'>" +
                            "<i class='fa fa-eye'></i>" +
                            "</a>" +
                            "&nbsp;&nbsp;" +
                            "<button type='button' style='display: none' title='审核成功' class='btn btn-success btn-circle checkSuccess'>" +
                            "<i class='fa fa-check'></i>" +
                            "</button>" +
                            "&nbsp;&nbsp;" +
                            "<button type='button' style='display: none' title='审核失败' class='btn btn-danger btn-circle checkFail'>" +
                            "<i class='fa fa-remove'></i>" +
                            "</button>",
                            "targets": -1
                        }
                    ],
                    "createdRow": function (row, data, index) {
                        _companyUserList.v.list.push(data);
                        if (data.checkStatus == 0) {
                            $('td', row).eq(0).html("<input type='checkbox' value=" + data.id + ">");
                        } else {
                            $('td', row).eq(0).html("");
                        }
                    },
                    rowCallback: function (row, data) {
                        switch (Number(data.checkStatus)) {
                            case 0:
                                $('td', row).eq(5).html('待审核');
                                break;
                            case 1:
                                $('td', row).eq(5).html('审核成功');
                                break;
                            case 2:
                                $('td', row).eq(5).html('审核失败');
                                break;
                        }

                        //渲染样式
                        if (data.checkStatus == 0) {
                            $('td', row).last().find(".checkSuccess").css("display", "");
                            $('td', row).last().find(".checkFail").css("display", "");
                        }

                        $('td', row).last().find(".edit").attr("href", 'backend/companyUser/show?flag=2&companyUserId=' + data.id);

                        $('td', row).last().find(".checkSuccess").click(function () {
                            $("#tempCheckStatus").val(1);
                            _companyUserList.fn.changeCheckStatus(data.id, 1);
                        });

                        $('td', row).last().find(".checkFail").click(function () {
                            $("input:checkbox").each(function (i) {
                                var val = $(this).val();
                                if (!isNaN(val) && val == data.id) {
                                    $(this).prop("checked", true);
                                    $('#companyUserId').val("");
                                    $("#tempCheckStatus").val(2);
                                    $("#delModal").modal("show");
                                } else {
                                    $(this).prop("checked", false);
                                }
                            });
                        });
                    },
                    "fnServerParams": function (aoData) {
                        aoData.mobile = $('#mobile').val();
                        aoData.nickName = $('#nickName').val();
                        aoData.type = $('#typeList option:selected').val();
                        aoData.checkStatus = $('#statusList option:selected').val();
                        aoData.isCheck = 1;
                    },
                    "fnDrawCallback": function (row) {
                        $leoman.uiform();
                    }
                });
            },
            changeCheckStatus: function (id, status) {
                var failReasonContent = $('#failReasonContent').val();
                var checkStatus = $("#tempCheckStatus").val();

                if (checkStatus == 2 && (null == failReasonContent || failReasonContent == '')) {
                    $leoman.notify("审核失败原因不能为空", "error");
                    return;
                } else {
                    $leoman.ajax("backend/companyUser/changeCheckStatus", {
                        "companyUserId": id,
                        "status": status
                    }, function (result) {
                        if (result == 1) {
                            $leoman.notify("操作成功", "success");
                            $("#delModal").modal("hide");
                            $('#companyUserId').val("");
                            _companyUserList.v.dTable.ajax.reload(null, false);
                        } else {
                            $leoman.notify("操作失败", "error");
                        }
                    });
                }
            },
            batchCheck: function () {
                var companyUserId = $('#companyUserId').val();
                if (null == companyUserId || companyUserId == '') {
                    var checkBox = $("#dataTables tbody tr").find('input[type=checkbox]:checked');
                    var ids = checkBox.getInputId();
                    _companyUserList.fn.deleteRow(checkBox, ids);
                } else {
                    _companyUserList.fn.changeCheckStatus(companyUserId, $('#tempCheckStatus').val());
                }
            },
            batchDel: function (status) {
                $("#tempCheckStatus").val(status);
                if (status == 1) {
                    _companyUserList.fn.batchCheck();
                } else {
                    var checkBox = $("#dataTables tbody tr").find('input[type=checkbox]:checked');
                    var ids = checkBox.getInputId();
                    if (ids.length > 0) {
                        $('#companyUserId').val("");
                        $("#delModal").modal("show");
                    }
                }
            },
            deleteRow: function (checkBox, ids) {
                if (ids.length > 0) {
                    var failReasonContent = $('#failReasonContent').val();
                    var checkStatus = $("#tempCheckStatus").val();

                    if (checkStatus == 2 && (null == failReasonContent || failReasonContent == '')) {
                        $leoman.notify("审核失败原因不能为空", "error");
                        return;
                    } else {
                        $leoman.ajax("backend/companyUser/batchCheck", {
                            ids: JSON.stringify(ids),
                            status: checkStatus,
                            failReasonContent: failReasonContent
                        }, function (result) {
                            if (result > 0) {
                                $("#delModal").modal("hide");
                                $leoman.notify("操作成功", "success");
                                _companyUserList.v.dTable.ajax.reload();
                            } else {
                                $leoman.notify("操作失败", "error");
                            }
                        });
                    }
                }
            }
        }
    }

    $(document).ready(function () {
        _companyUserList.fn.init();
    });

</script>

</html>